package cn.kkcxy.blog.system.service.impl.sys;

import cn.kkcxy.blog.core.enums.DeletedEnum;
import cn.kkcxy.blog.core.enums.StatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kkcxy.blog.core.entity.sys.SysPermission;
import cn.kkcxy.blog.system.service.sys.SysPermissionService;
import cn.kkcxy.blog.system.mapper.sys.SysPermissionMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author kk
* @description 针对表【sys_permission】的数据库操作Service实现
* @createDate 2024-09-11 00:50:27
*/
@Slf4j
@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService{

    /**
     * sys permission mapper
     */
    @Resource
    private SysPermissionMapper sysPermissionMapper;

    /**
     * @description: 获取权限列表
     * @author: kkcxy
     * @date: 2024/10/7 21:29
     * @param: [userId]
     * @return: java.util.List<java.lang.String>
     **/
    @Override
    public List<String> getPermissionList(Long userId) {
        log.info("获取权限列表 id: {}", userId);
        return sysPermissionMapper.getPermissionList(userId);
    }

    /**
     * @description: 获取路由列表
     * @author: kkcxy
     * @date: 2024/10/23 21:06
     * @param: []
     * @return: java.util.List<cn.kkcxy.blog.core.entity.sys.SysPermission>
     **/
    @Override
    public List<SysPermission> getRouterList(List<Long> routerIds) {
        LambdaQueryWrapper<SysPermission> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .in(SysPermission::getType, 0, 1)
                .in(SysPermission::getId, routerIds)
                .eq(SysPermission::getStatus, StatusEnum.ENABLE.type)
                .eq(SysPermission::getDeleted, DeletedEnum.NO.getStatus());
        return sysPermissionMapper.selectList(queryWrapper);
    }

    /**
     * @description: 查询用户拥有的路由id
     * @author: kkcxy
     * @date: 2024/10/27 2:07
     * @param: [userId]
     * @return: java.util.List<java.lang.Long>
     **/
    @Override
    public List<Long> getRouterIdsByUserId(Long userId) {
        return sysPermissionMapper.getRouterIdsByUserId(userId);
    }
}




